import requests


class SendMethod(object):

    @staticmethod
    def send_method(url: str, method: str, params=None, data=None, json=None, headers=None):
        """
        发起get或者post请求的方法
        """
        # 判断是get请求方式
        if method.lower() == 'get':
            # 按照get进行请求
            response = requests.get(url, params=params, headers=headers)
        elif method.lower() == 'post':
            # 判断传参方式是data还是json
            if data is not None:
                response = requests.post(url, data=data, headers=headers)
            elif json is not None:
                response = requests.post(url, json=json, headers=headers)
            else:
                response = requests.post(url, headers=headers)
        else:
            print("目前请求方式仅支持get和post")
            return None

        result = {}

        result["status_code"] = response.status_code
        result["body"] = response.json()
        result["headers"] = response.headers
        result['response_time'] = response.elapsed.microseconds / 1000
        return result


if __name__ == '__main__':
    url = "http://47.108.206.100:8085/sso/getAuthCode"
    payload = {"telephone":"1355678965"}

    print(SendMethod.send_method(url, "get", payload))
